package com.lswms.modules.lswms.service.impl.WCS;

import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.lswms.modules.lswms.dao.WCS.WCSDao;
import com.lswms.modules.lswms.service.WCS.WCSService;

@Service
public class WCSServiceImpl implements WCSService {

	@Autowired
	WCSDao wcsDao ;
	
	@Override
	public List<Map<String, Object>> getDDJ() {
		List<Map<String,Object>> list = wcsDao.getDDJ();
		return list;
	}

	@Override
	public String changeDDJStatus(Map map) {
		String dvc_No = (String)map.get("DVC_NO");
		String status = (String)map.get("status");
		if(StringUtils.isBlank(dvc_No)) {
			return "堆垛机号不能为空" ;
		}
		if(StringUtils.isBlank(status)) {
			return "状态不能为空" ;
		}
		wcsDao.changeDDJStatus(dvc_No,status);
		return null;
	}

	@Override
	public List<Map<String, Object>> getWCSTask() {
		List<Map<String,Object>> list = wcsDao.getWCSTask();
		return list;
	}

	@Override
	@Transactional(rollbackFor = Exception.class)
	public String changeWCS(Map map) {
		String taskid = (String)map.get("taskid");
		String type = (String)map.get("type");
		if(StringUtils.isBlank(taskid)) {
			return "WCS的任务号不能未空" ;
		}
		if(StringUtils.isBlank(type)) {
			return "按钮操作类型不能不能为空" ;
		}
		
		// 查找任务号是否存在
		List<Map<String,Object>> list = wcsDao.getWCSTaskBy(taskid);
		if(list.size() ==0) {
			return "选择的WCS任务号："+taskid+"不存在或已完成" ;
		}
		if(type.equals("DONE")) {
			wcsDao.updateWCSTaskStatus(taskid,"9");
		}else if(type.equals("DELETE")) {
			wcsDao.deleteWCSTaskBy(taskid) ;
		}
		
		return null;
	}
}
